package itheima;







import com.fasterxml.jackson.databind.ObjectMapper;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/json")
public class JsonServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String str = req.getParameter("jso");
        ObjectMapper obj=new ObjectMapper();
        JsonUser user = obj.readValue(str, JsonUser.class);
        System.out.println(user);
        //封装一个u对象的数据
        JsonUser u=new JsonUser();
        u.setName("lisi");
        u.setAge(19);
        String json = obj.writeValueAsString(u);
        //响应给客户端
        resp.getWriter().write(json);
    }
}
